/**
 * Moondance UML modeling tool
 * 
 * @author Dascalu Laurentiu (dascalu.laurentziu@gmail.com).
 * 
 * This program is free software; you can redistribute it and
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package ro.pub.cs.se.moondance;

import java.util.Random;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.ui.IWorkbench;

import ro.pub.cs.se.moondance.model.UMLDiagram;

// Moondance singleton for storing data.
public class MoondanceData {
	public static final IProgressMonitor DEFAULT_MONITOR = new NullProgressMonitor();

	// Current viewed diagram reference
	private static UMLDiagram diagrameReference = null;

	// Current workbench reference; used only in the operation of
	// importing UML diagrams from XMI files
	private static IWorkbench workbench;

	public static void init() {
	}

	public static void setCurrentDiagram(UMLDiagram diagram) {
		diagrameReference = diagram;
	}

	public static UMLDiagram getCurrentDiagram() {
		return diagrameReference;
	}

	public static void setWorkbench(IWorkbench workbench) {
		MoondanceData.workbench = workbench;
	}

	public static IWorkbench getWorkbench() {
		return workbench;
	}

	private static Random randGenerator = new Random();

	/**
	 * Returns a random string; used to generate entities identifiers when
	 * exporting UML diagrams to XMI format.
	 */
	public static String newRandomString() {
		char c[] = new char[23];

		c[0] = '_';

		for (int i = 1; i < 23; i++)
			c[i] = (char) (randGenerator.nextInt('z' - 'a' + 1) + 'a');

		return new String(c);
	}

	public static void exitWithError() {
		System.out.println("invalid execution, please report");
		System.exit(1);
	}
}
